package com.gem.service.impl;

import com.gem.domain.StuCareer;
import com.gem.mapper.CareerMapper;
import com.gem.service.CareerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@SuppressWarnings("all")
public class CareerServiceImpl implements CareerService {

    @Autowired
    CareerMapper careerMapper;

    @Override
    public List<StuCareer> findByCid(Integer cId) {
        return careerMapper.showStuCareer(cId);
    }

    //展示该班级所有学生就业情况
    @Override
    public List<StuCareer> showStuCareer(Integer careerClassId, Object o, Object o1) {
        return careerMapper.showStuCareer(careerClassId);
    }

    @Override
    //服务层完成搜索需要的操作
    public List<StuCareer> searchStuCareer(StuCareer stuCareer, Object o, Object o1) {


        //学生班级Id
        stuCareer.setCareerClassId(stuCareer.getCareerClassId());
        System.out.println("在搜索层的careerClassId是:" + stuCareer.getCareerClassId());


        //搜索学生姓名
        if (stuCareer.getCareerStuName() != null) {
            if ("null".equals(stuCareer.getCareerStuName()) || stuCareer.getCareerStuName().length() == 0) {
                stuCareer.setCareerStuName(null);
            } else {
                stuCareer.setCareerStuName(stuCareer.getCareerStuName().replaceAll(" ", ""));
                stuCareer.setCareerStuName("%" + stuCareer.getCareerStuName() + "%");
            }
        }

        //搜索就业公司
        if (stuCareer.getCareerCompany() != null) {
            if ("null".equals(stuCareer.getCareerCompany()) || stuCareer.getCareerCompany().length() == 0) {
                stuCareer.setCareerCompany(null);
            } else {
                stuCareer.setCareerCompany(stuCareer.getCareerCompany().replaceAll(" ", ""));
                stuCareer.setCareerCompany("%" + stuCareer.getCareerCompany() + "%");
            }
        }

        //搜索就业城市
        if (stuCareer.getCareerCity() != null) {
            if ("null".equals(stuCareer.getCareerCity()) || stuCareer.getCareerCity().length() == 0) {
                stuCareer.setCareerCity(null);
            } else {
                stuCareer.setCareerCity(stuCareer.getCareerCity().replaceAll(" ", ""));
                stuCareer.setCareerCity("%" + stuCareer.getCareerCity() + "%");
            }
        }

       List<StuCareer> pageInfo = null;
        try {
            pageInfo = careerMapper.searchCareer(stuCareer);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pageInfo;
    }

    @Override
    //保存添加的学生就业情况
    public void updateStuCareer(StuCareer stuCareer) {

        careerMapper.updateStuCareer(stuCareer);
    }

    @Override
    public void saveExcel(StuCareer stuCareer) {

    }


}
